package homework.day06;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 聊天室服务端类
 *
 * @author Luka
 * @date 2021/06/02 20:27
 **/
public class Server1 {
    private ServerSocket server;
    public Server1() {
        try {
            System.out.println("正在启动服务器...");
            server = new ServerSocket(8088);
            System.out.println("服务器启动完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void start(){
        try {
            System.out.println("等待客户端连接...");
            Socket socket = server.accept();
            System.out.println("一个客户连接了!");

            InputStream in = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(in);
            BufferedReader br = new BufferedReader(isr);

           // String line;
           // while ((line = br.readLine())!=null){
            String line;
            line = br.readLine();
            System.out.println(line);
            //}
            //br.close();
//            String line = br.readLine();//读取客户端发送过来的一行字符串
//            System.out.println("客户端说:"+line);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Server server = new Server();
        server.start();
    }
}